# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from decimal import Decimal
from typing import Union, List
from fastapi import Query
from pydantic import BaseModel, Field


class KnowDatasetSearchIn(BaseModel):
    """ 数据搜索参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    archive_id: int = Query(default=0, ge=0, description="文档ID")
    keyword: Union[str, None] = Query(default=None, description="关键词")
    status: Union[int, None] = Query(ge=0, default=None, description="学习状态: [1=排队中,2=学习中,3=学习成功,4=学习失败]")


class KnowDatasetDetailIn(BaseModel):
    """ 数据详情参数 """
    uuids: str = Query(..., description="数据UUID")

    class Config:
        json_schema_extra = {
            "example": {
                "uuids": "0bdbaa93-7905-4ae6-a220-79c8f592ca3e"
            }
        }


class KnowDatasetUuidsIn(BaseModel):
    """ 数据主键参数 """
    uuids: List[str] = Field(..., description="数据ID")

    class Config:
        json_schema_extra = {
            "example": {
                "uuids": ["1", "2", "8"]
            }
        }


"""--------------- Separator ---------------"""


class KnowDatasetAnnex(BaseModel):
    """ 数据附件 """
    id: str = Field(default="", max_length=64, description="附件ID")
    type: str = Field(..., min_length=1, max_length=32, description="附件类型")
    name: str = Field(..., min_length=1, max_length=200, description="附件名称")
    path: str = Field(..., min_length=1, max_length=250, description="附件路径")
    ext: str = Field(..., min_length=1, max_length=5000, description="附件扩展")
    size: int = Field(..., ge=0, description="附件大小")
    sort: int = Field(..., ge=0, description="附件排序")
    question: str = Field(default="", max_length=5000, description="附件描述")

    class Config:
        json_schema_extra = {
            "example": {
                "id": "32cea0b8-94b4-4f7d-aca1-151e6a930dc6",
                "type": "image",
                "name": "test.png",
                "path": "https://www.xx.com/aa.png",
                "ext": "jpg",
                "size": 100,
                "sort": 0,
                "question": "附件描述信息"
            }
        }


"""--------------- Separator ---------------"""


class KnowDatasetListVo(BaseModel):
    """ 数据列表VO """
    id: str = Field(description="UUID")
    question: str = Field(description="问题")
    answer: str = Field(description="答复")
    know: str = Field(description="所属知识库")
    know_code: str = Field(description="知识库编号")
    vector_alias: str = Field(description="向量模型别名")
    vector_model: str = Field(description="向量模型编码")
    dimension: int = Field(description="向量维度")
    character: int = Field(description="字符数量")
    use_points: int = Field(description="消耗积分")
    use_tokens: int = Field(description="消耗Tokens")
    status: int = Field(description="训练状态")
    create_time: str = Field(description="创建时间")
    update_time: str = Field(description="更新时间")
    user: dict = Field(description="导入用户")

    class Config:
        json_schema_extra = {
            "example": {
                "id": "5bdd304b-b6d0-408b-bb7f-90d945b2d818",
                "question": "广州大学城道路改造项。",
                "answer": "",
                "know": "TTY",
                "know_code": "4456724566",
                "vector_alias": "智谱清言",
                "vector_model": "zhipu:embedding-3",
                "dimension": 2048,
                "character": 79,
                "use_points": 1,
                "use_tokens": 88,
                "status": 3,
                "create_time": "2025-04-14 22:46:08",
                "update_time": "2025-04-14 22:46:08",
                "user": {
                    "sn": "",
                    "nickname": "",
                    "mobile": "",
                    "avatar": ""
                }
            }
        }


class KnowDatasetDetailVo(BaseModel):
    """ 数据详情VO """
    id: str = Field(description="UUID")
    question: str = Field(description="问题")
    answer: str = Field(description="答复")
    annex: List[KnowDatasetAnnex] = Field(description="附件")

    class Config:
        json_schema_extra = {
            "example": {
                "id": "0bdbaa93-7905-4ae6-a220-79c8f592cab3",
                "question": "",
                "answer": "",
                "annex": [
                    {
                        "id": "32cea0b8-94b4-4f7d-aca1-151e6a9302c6",
                        "type": "image",
                        "name": "test.png",
                        "path": "https://www.xx.com/aa.png",
                        "ext": "png",
                        "size": 100,
                        "sort": 0,
                        "question": "附件描述信息"
                    }
                ]
            }
        }
